﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Boco.Digg.Utilities
{
	public class Utility
	{
		public static DateTime UnixTimeToDateTime(int unixTime)
		{
			if (unixTime < 0)
				throw new ArgumentOutOfRangeException("unixTime",
					"The number of seconds since Jaanuary 01 1970 must be equal to or greater than 0");
			DateTime date = DateTime.Parse("1970/01/01");
			return date.AddSeconds(unixTime);
		}

		public static int DateTimeToUnixTime(DateTime date)
		{
			DateTime epoch = DateTime.Parse("1970/01/01");
			TimeSpan diff = (date - epoch);
			if (diff.Seconds < 0)
				throw new ArgumentOutOfRangeException();

			return (int)diff.TotalSeconds;
		}
	}
}
